import { GetterTree } from 'vuex'
import { Istate } from '../../interface'
const getters: GetterTree<Istate, Istate> = {
  getuser: state => state.user,
  getusers: ({ users }) => users ? users.rows : [],
  getactivity: ({ activity }) => activity ? activity.rows : [],
  getarticle: ({ article }) => article ? article.rows : [],
  getquestion: ({ question }) => question ? question.rows.map(v => {
    const { testcases = [] } = v
    const t = testcases?.filter(e => {
      return !e.isshow
    })
    return {
      ...v,
      example: t
    }
  }) : [],
  getquestionbank: ({ questionbank }) => questionbank ? questionbank.rows : [],
  getlabel: ({ label }) => label ? label.rows : [],
  getuserscount: ({ users }) => Number(users?.count),
  getquestioncount: ({ question }) => Number(question?.count),
  getquestionbankcount: ({ questionbank }) => Number(questionbank?.count),
  getactivitycount: ({ activity }) => Number(activity?.count),
  getarticlecount: ({ article }) => Number(article?.count),
  getlabelcount: ({ label }) => Number(label?.count),
  getteam: ({ team }) => team ? team.rows : [],
  getteamcount: ({ team }) => team ? team.count : 0,
  getnotice: ({ notice }) => notice ? notice.rows : [],
  getnoticecount: ({ notice }) => notice ? notice.count : 0,
  getisseecount: ({ notice }) => notice ? notice.isseecount : 0,
  gettime: ({ time }) => time ? time : Date.now(),
  // 我的练习题目
  getMyPractiseQuestion: state => state.myPractiseQuestion?.map(e => ({ ...e, ...e.question })),
  getMyPractiseQuestionCount: ({ myPractiseQuestion }) => Number(myPractiseQuestion?.length),
}
export default getters